package model;

import java.util.List;

import result.Result;

import model.thread.ThreadUtil;
import business.ViewLogger;
import business.iservices.*;
import business.coding.*;

/**
 * Modelo para la vista de prueba de corps
 * @author 53385255R
 *
 */
public class ManualCodeCorpTestModel {
	

	String corpTest;
	List<CenterWeightAndWords> centers;
	String selected_center_code;
	
	private ThreadUtil threadUtil;

	public ManualCodeCorpTestModel() {
		threadUtil = new ThreadUtil();
	}
	
	public String getCorpTest() {
		return corpTest;
	}
	public void setCorpTest(String corpTest) {
		this.corpTest = corpTest;
	}
	
	public void codeCorpAndGetCenters(int autoThCtxt) {
		Result<CenterWeightAndWords> res = FactoryBusinessSrv.getInstance().getCodeService().parseCodeNewCorp(corpTest, autoThCtxt);
		if (res.is_ok()) {
			centers = res.get_transfers();
		} else {
			centers.clear();
			ViewLogger.getInstance().error("Error: no se han podido obtener los centros candidatos. " + res.get_message());
		}
		
		//threadUtil.executeWithThread(threadUtil.METHOD_PARSENEWCORP, new String[] { corpTest});
		//ViewLogger.getInstance().info(FactoryBusinessSrv.getInstance().getCacheService().selectLastMaescorpIdCorp().get_transfers().get(0) + "");
	}

	public List<CenterWeightAndWords> getCenters() {
		return centers;
	}

	public void setCenters(List<CenterWeightAndWords> centers) {
		this.centers = centers;
	}

	public String getSelected_center_code() {
		return selected_center_code;
	}

	public void setSelected_center_code(String center_code) {
		this.selected_center_code = center_code;
	}
	
	public void insert() {
		boolean fnd = false;
		int i = 0;
		CenterWeightAndWords cen = null;
		while (!fnd && centers.size() > i) {
			if (centers.get(i).getCenter().getCODE().equals(selected_center_code)) {
				cen = centers.get(i);
				fnd = true;
			}
			i++;
		}
		
		if (fnd)
			FactoryBusinessSrv.getInstance().getCodeService().insertCodeCorp(corpTest, cen);
	}
	
	
	
	
	
}
